package models

import (
	"dache-server/basic/config"
	"gorm.io/gorm"
	"time"
)

type Users struct {
	Id        uint           `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	Username  string         `gorm:"column:username;type:varchar(255);not null;" json:"username"`
	Password  string         `gorm:"column:password;type:varchar(255);not null;" json:"password"`
	Mobile    string         `gorm:"column:mobile;type:varchar(11);not null;" json:"mobile"`
	UserType  uint           `gorm:"column:user_type;type:int UNSIGNED;comment:用户类型：1：用户 2：司机 3：管理员;not null;default:0;" json:"user_type"` // 用户类型：1：用户 2：司机 3：管理员
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (u *Users) GetUserByMobile() error {
	return config.DB.Where("mobile = ?", u.Mobile).Error
}
